package com.glamour.hlcity.component.task.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.glamour.hlcity.common.enums.ErrorCodeEnum;
import com.glamour.hlcity.common.util.StringUtil;
import com.glamour.hlcity.component.task.api.ExecuteUnit;
import com.glamour.hlcity.component.task.common.TaskException;

public class RunnableUnit implements Runnable {
	private final static Log LOG=LogFactory.getLog(RunnableUnit.class);
	private ExecuteUnit executeUnit;
	private String type;
	private String seqno;
	
	public RunnableUnit(ExecuteUnit executeUnit,String type,String seqno){
		this.executeUnit=executeUnit;
		this.type=type;
		this.seqno=seqno;
	}

	@Override
	public void run() {
		if(this.executeUnit==null || StringUtil.isNull(type,seqno)){
			throw new TaskException(ErrorCodeEnum.SYS_ERROR,"执行单元参数为空，不符合条件");
		}
		try{
			executeUnit.execute(type, seqno);
		}catch(TaskException taskE){
			//针对M010001异常进行监控
			LOG.error("执行单元执行时发生异常",new TaskException(ErrorCodeEnum.M010001,taskE));
			//吃掉该异常，不抛出
			//throw taskE;
		}
		
	}

}
